package com.zm.demo.javaagent.premain;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

/**
 * @author zoum
 * @create 2019/12/26 10:43
 */
public class SimpleAgentMain {

    public static void main(String[] args) throws Exception{
        System.out.println("执行main..");
        fetch("http://www.baidu.com");
        fetch("http://www.jd.com");
    }


    public static void fetch(String address) throws IOException{
        final URL url = new URL(address);
        final URLConnection urlConnection = url.openConnection();
        try (final BufferedReader in = new BufferedReader(
                new InputStreamReader(urlConnection.getInputStream())
        )){
            String inputLine = null;
            final StringBuffer sb = new StringBuffer();
            while ( (inputLine = in.readLine()) != null){
                sb.append(inputLine);
            }

            System.out.println("Content size:" + sb.length());
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
